<template>
  <div class="pop-dialog-container">
    <div class="pop-dialog-main">
      <el-card>
        <div slot="header" class="clearfix">
          <span>招聘岗位信息</span>
        </div>
        <el-form label-position="right" :model="applicationRecordForm" :label-width="formLabelWidth" disabled="disabled">
          <el-row>
            <el-col :span="11">
              <el-form-item label="企业名称">
                <el-input v-model="applicationRecordForm.enterpriseName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="招聘岗位名称">
                <el-input v-model="applicationRecordForm.jobDescriptionName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card>
        <div slot="header" class="clearfix">
          <span>基本信息</span>
        </div>
        <el-form label-position="right" :model="candidateForm" :label-width="formLabelWidth" disabled="disabled">
          <el-row>
            <el-col :span="11">
              <el-form-item label="用户名">
                <el-input v-model="candidateForm.username"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="姓名">
                <el-input v-model="candidateForm.name"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="密码">
                <el-input v-model="candidateForm.password"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="性别">
                <el-select v-model="candidateForm.gender" placeholder="请选择性别">
                  <el-option label="男" :value="1"></el-option>
                  <el-option label="女" :value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="出生日期">
                <el-input v-model="candidateForm.birthDate"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="联系电话">
                <el-input v-model="candidateForm.contactPhone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="邮箱">
                <el-input v-model="candidateForm.email"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="省/市/区">
                <el-cascader
                    v-model="provinceCityArea"
                    :options="provinceCityAreaOptions"
                    :props="{ expandTrigger: 'hover', value: 'code', label: 'name' }"></el-cascader>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="家庭地址">
                <el-input v-model="candidateForm.address"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card>
        <div slot="header" class="clearfix">
          <span>教育经历</span>
        </div>
        <el-form label-position="right" :model="educationForm" :label-width="formLabelWidth" disabled="disabled">
          <el-row>
            <el-col :span="11">
              <el-form-item label="应聘者姓名">
                <el-input v-model="educationForm.candidateName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="学校名称">
                <el-input v-model="educationForm.schoolName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="学历">
                <el-select v-model="educationForm.degree" placeholder="请选择学历">
                  <el-option label="初中" :value="10"></el-option>
                  <el-option label="高中" :value="20"></el-option>
                  <el-option label="本科" :value="30"></el-option>
                  <el-option label="硕士研究生" :value="40"></el-option>
                  <el-option label="博士研究生" :value="50"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="开始日期">
                <el-input v-model="educationForm.startDate"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="结束日期">
                <el-input v-model="educationForm.endDate"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card>
        <div slot="header" class="clearfix">
          <span>工作经历</span>
        </div>
        <el-form label-position="right" :model="workExperienceForm" :label-width="formLabelWidth" disabled="disabled">
          <el-row>
            <el-col :span="11">
              <el-form-item label="应聘者姓名">
                <el-input v-model="workExperienceForm.candidateName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="公司名称">
                <el-input v-model="workExperienceForm.company"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="岗位">
                <el-input v-model="workExperienceForm.position"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="开始日期">
                <el-input v-model="workExperienceForm.startDate"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="结束日期">
                <el-input v-model="workExperienceForm.endDate"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="22">
              <el-form-item label="岗位职责" prop="responsibilities">
                <el-input type="textarea" :rows="3" v-model="workExperienceForm.responsibilities"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card>
        <div slot="header" class="clearfix">
          <span>技能证书</span>
        </div>
        <el-form label-position="right" :model="skillCertificateForm" :label-width="formLabelWidth" disabled="disabled">
          <el-row>
            <el-col :span="11">
              <el-form-item label="应聘者姓名">
                <el-input v-model="skillCertificateForm.candidateName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="证书名称">
                <el-input v-model="skillCertificateForm.certificateName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="颁发机构">
                <el-input v-model="skillCertificateForm.issuingAuthority"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="颁发时间">
                <el-input v-model="skillCertificateForm.issueDate"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="到期日期">
                <el-input v-model="skillCertificateForm.expiryDate"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card>
        <div slot="header" class="clearfix">
          <span>培训记录</span>
        </div>
        <el-form label-position="right" :model="trainingRecordForm" :label-width="formLabelWidth" disabled="disabled">
          <el-row>
            <el-col :span="11">
              <el-form-item label="应聘者姓名">
                <el-input v-model="trainingRecordForm.candidateName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="培训名称">
                <el-input v-model="trainingRecordForm.trainingName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="培训日期">
                <el-input v-model="trainingRecordForm.trainingDate"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="培训时长">
                <el-input v-model="trainingRecordForm.durationHours"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="培训供应商">
                <el-input v-model="trainingRecordForm.provider"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="22">
              <el-form-item label="培训内容" prop="trainingDescription">
                <el-input type="textarea" :rows="3" v-model="trainingRecordForm.trainingDescription"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>
    <div class="pop-dialog-footer">
      <el-row>
        <el-col :span="12" :offset="6">
          <div class="form-button-container">
            <el-button @click="onBack" type="primary">关闭</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import candidateApi from '@/api/candidateApi'
import areas from "@/locales/area.json";
import educationApi from "@/api/educationApi";
import workExperienceApi from "@/api/workExperienceApi";
import skillCertificateApi from "@/api/skillCertificateApi";
import trainingRecordApi from "@/api/trainingRecordApi";
import applicationRecordApi from "@/api/applicationRecordApi";
export default {
  name: 'CandidateViewAll',
  props: ['id'],
  mixins: [
  ],
  data () {
    return {
      applicationRecordForm: {
      },
      candidateForm: {
      },
      provinceCityArea: [],
      provinceCityAreaOptions: areas.provinces,
      educationForm: {
      },
      workExperienceForm: {
      },
      skillCertificateForm: {
      },
      trainingRecordForm: {
      }
    }
  },
  created () {
    if (this.id) {
      applicationRecordApi.findById(this.id)
          .then(resp => {
            if (resp && resp.code === 1) {
              this.applicationRecordForm = resp.data
            } else {
              this.$message.error('获取数据失败')
            }
          })
          .catch(error => {
            console.error('获取数据失败:', error)
          })
      candidateApi.findById(this.id)
          .then(resp => {
            if (resp && resp.code === 1) {
              this.candidateForm = resp.data
              this.provinceCityArea = []
              if (this.candidateForm.province) {
                this.provinceCityArea.push(this.candidateForm.province)
              }
              if (this.candidateForm.city) {
                this.provinceCityArea.push(this.candidateForm.city)
              }
              if (this.candidateForm.area) {
                this.provinceCityArea.push(this.candidateForm.area)
              }
            } else {
              this.$message.error('获取数据失败')
            }
          })
          .catch(error => {
            console.error('获取数据失败:', error)
          })
      educationApi.findById(this.id)
          .then(resp => {
            if (resp && resp.code === 1) {
              this.educationForm = resp.data
            } else {
              this.$message.error('获取数据失败')
            }
          })
          .catch(error => {
            console.error('获取数据失败:', error)
          })
      workExperienceApi.findById(this.id)
          .then(resp => {
            if (resp && resp.code === 1) {
              this.workExperienceForm = resp.data
            } else {
              this.$message.error('获取数据失败')
            }
          })
          .catch(error => {
            console.error('获取数据失败:', error)
          })
      skillCertificateApi.findById(this.id)
          .then(resp => {
            if (resp && resp.code === 1) {
              this.skillCertificateForm = resp.data
            } else {
              this.$message.error('获取数据失败')
            }
          })
          .catch(error => {
            console.error('获取数据失败:', error)
          })
      trainingRecordApi.findById(this.id)
          .then(resp => {
            if (resp && resp.code === 1) {
              this.trainingRecordForm = resp.data
            } else {
              this.$message.error('获取数据失败')
            }
          })
          .catch(error => {
            console.error('获取数据失败:', error)
          })
    }
  },
  methods: {
    onBack () {
      this.$emit('close-candidate-view-all-event')
    }
  }
}
</script>

<style lang="scss">
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}
</style>